/**
 * 
 */
package com.kth.subtranslator.ui;

import java.awt.GridLayout;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map.Entry;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.kth.subtranslator.ITranslateDriverConfiguration;

/**
 * @author Kevin Thackray
 *
 */
public class ConfigurationPanel extends JPanel {
	
	private ITranslateDriverConfiguration configuration;
	
	/**
	 * 
	 */
	public ConfigurationPanel() {
//		setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
		setLayout( new GridLayout(2, 2) );
	}
	
	/**
	 * @param configuration the configuration to set
	 */
	public void setConfiguration(ITranslateDriverConfiguration configuration) {
		this.configuration = configuration;
		refreshUI();
	}
	
	private void refreshUI() {
		removeAll();
		if (configuration != null) {
			for (Entry<String, Object> entry : configuration.getOptions().entrySet()) {
				JPanel p = new JPanel();
				p.setBorder(BorderFactory.createEtchedBorder());
				p.setLayout(new BoxLayout(p, BoxLayout.LINE_AXIS));
				p.add(new JLabel(entry.getKey()));
				
				if (entry.getValue() instanceof Collection ) {
					Collection<Object> values = (Collection<Object>)entry.getValue();
					JComboBox combo = new JComboBox();
					for (Iterator iterator = values.iterator(); iterator
							.hasNext();) {
						Object object = (Object) iterator.next();
						combo.addItem(object.toString());
					}
					p.add(combo);
				}
				add(p);
			}
		}
	}

}
